/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function(head) {
    if(head == null || head.next == null) return head
    let p = head, q = head.next, r = q
    while(r.next !== null) r = r.next
    const iter = (p, q) => {
        if(p == r) {
            console.log(p.val, "==", q.val);
            return
        }
        let temp = r.next
        r.next = p
        p.next = temp
        p = q
        q = p.next
        iter(p, q)
    }
    iter(p, q)
    return p
};